﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TextTemplating;
using System.CodeDom.Compiler;

namespace Clarius.PresentationModel
{
	internal class ToolTemplateHost : ITextTemplatingEngineHost
	{
		IServiceProvider provider;

		public ToolTemplateHost(IServiceProvider provider, string templateFile)
		{
			this.provider = provider;
			this.TemplateFile = templateFile;
			this.Extension = ".cs";
			this.Encoding = Encoding.UTF8;
		}

		public CompilerErrorCollection Errors { get; private set; }
		public string Extension { get; private set; }
		public Encoding Encoding { get; private set; }

		public object GetHostOption(string optionName)
		{
			return null;
		}

		public bool LoadIncludeText(string requestFileName, out string content, out string location)
		{
			throw new NotImplementedException();
		}

		public void LogErrors(CompilerErrorCollection errors)
		{
			this.Errors = errors;
		}

		public AppDomain ProvideTemplatingAppDomain(string content)
		{
			return AppDomain.CurrentDomain;
		}

		public string ResolveAssemblyReference(string assemblyReference)
		{
			return assemblyReference;
		}

		public Type ResolveDirectiveProcessor(string processorName)
		{
			throw new NotImplementedException();
		}

		public string ResolveParameterValue(string directiveId, string processorName, string parameterName)
		{
			throw new NotImplementedException();
		}

		public string ResolvePath(string path)
		{
			return path;
		}

		public void SetFileExtension(string extension)
		{
			this.Extension = extension;
		}

		public void SetOutputEncoding(Encoding encoding, bool fromOutputDirective)
		{
			this.Encoding = encoding;
		}

		public IList<string> StandardAssemblyReferences
		{
			get
			{
				return new List<string>
				{
					typeof(System.Object).Module.FullyQualifiedName, 
					typeof(System.Uri).Module.FullyQualifiedName, 
					this.GetType().Module.FullyQualifiedName,
				};
			}
		}

		public IList<string> StandardImports
		{
			get 
			{
				return new List<string>
				{
					"System"
				};
			}
		}

		public string TemplateFile { get; private set; }
	}
}
